import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isShowLogin: false,
    user: null,
    // 我创建的歌单
    createList: [],
    // 我收藏的歌单
    addLlist: [],
    uid: null,
    cookie: '',
    isloading: false,
    // 注册界面显示隐藏
    isShowRegister: false
  },
  mutations: {
    hiddenLogin (state) {
      state.isShowLogin = false
    },
    showLogin (state) {
      state.isShowLogin = true
    },
    showRegister (state) {
      state.isShowRegister = true
    },
    hiddenRegister (state) {
      state.isShowRegister = false
    },
    addUser (state, obj) {
      state.user = obj;
      state.uid = state.user.profile.userId;
      state.cookie = obj.cookie;
    },
    showLoading (state) {
      state.isloading = true
    },
    hiddenLoading (state) {
      state.isloading = false
    }
  },
  getters: {
    getShowLogin (state) {
      return state.isShowLogin
    },
    getShowRegister (state) {
      return state.isShowRegister
    },
    // 用户图像
    getAvatar (state) {
      let avatar = '';
      if (localStorage.getItem('avatar')) {
        avatar = localStorage.getItem('avatar');
        return avatar;
      }
      avatar = state.user && state.user.profile.avatarUrl;
      return avatar
    },
    // 用户名称
    getUserName (state) {
      let nickname = '';
      if (localStorage.getItem('nickname')) {
        nickname = localStorage.getItem('nickname');
        return nickname;
      }
      nickname = state.user && state.user.profile.nickname;
      return nickname;
    },
    // 保存cookie
    getCookie (state) {
      if (localStorage.getItem('cookie')) {
        state.cookie = localStorage.getItem('cookie');
      }
      return state.cookie;
    },
    // 获取用户id
    getUserId (state) {
      if (localStorage.getItem('uid')) {
        state.uid = localStorage.getItem('uid');
      }
      return state.uid
    }
  },
  actions: {
  },
  modules: {
  }
})
